package com.kaibes.module.file.local;

import java.io.File;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FileConfig implements InitializingBean {
    
    @Value("${kaibes.platform.file.location:files}")
    private String location;
    
    public String getCache() {
        return new File(location).getAbsolutePath()+"/.cache/";
    }
    
    public File getFile(String filename) {
		return new File(location, filename);
	}
	
	public String getPath(String filename) {
		return getFile(filename).getAbsolutePath();
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		File file = new File(location);
        if (!file.exists()) {
            file.mkdirs();
        }
        location = file.getPath();
	}
    
}
